//
// Created by Administrator on 2021/11/13.
// May Saint Diana bless you!
//
#include <iostream>
#include <vector>
#include <unordered_map>
#include <string>

using namespace std;

class Solution {
public:
    vector<vector<string>> findDuplicate(vector<string> &paths) {
        unordered_map<string, vector<string>> contentToFile;
        for (const string &path:paths) {
            unsigned int space = path.find(' ');  // 第一个空格
            string basePath = path.substr(0, space); // 路径
            unsigned int index = space;
            while (index < path.size()) {
                auto left = path.find('(', index); // 左括号
                auto right = path.find(')', index); // 右括号
                string file = path.substr(index + 1, left - index - 1); // 文件名
                string content = path.substr(left + 1, right - left - 1); // 文件内容
                contentToFile[content].push_back(basePath + '/' + file);
                index = right + 1;
            }
        }
        vector<vector<string>> ans;
        for (auto &kv:contentToFile) {
            if (kv.second.size() > 1) {
                ans.push_back(kv.second);
            }
        }
        return ans;
    }
};

int main() {
    vector<string> paths{"root/a 1.txt(abcd) 2.txt(efgh)",
                         "root/c 3.txt(abcd)",
                         "root/c/d 4.txt(efgh)",
                         "root 4.txt(efgh)"};
    Solution solution;
    auto ans = solution.findDuplicate(paths);
    for (const auto &row:ans) {
        for (const auto &x:row) {
            cout << x << " ";
        }
        cout << endl;
    }
    return 0;
}


